
function loadkv(str)
	local stack = {}
	local key = {}
	local value = {}
	local root = {}
	local i = 1
	local str_len = string.len(str)
	local tkey = {}
	while true do
		if i > str_len then
			break
		end
		local char = string.sub(str,i,i)
		local len = #stack
		local bottom = stack[len]
		if char == '\"' then
			if len < 1 then
				table.insert(stack,i)
			else
				if string.sub(str,bottom,bottom)~='\"' then
					table.insert(stack,i)
				else
					table.remove(stack)
					if #key == #value then
						table.insert(key,string.sub(str,bottom+1,i-1))
					else
						table.insert(value,string.sub(str,bottom+1,i-1))
						root[key[#key]] = value[#value]
					end
				end
			end
			i = i + 1
		elseif char == '{' then
			table.insert(stack,i)
			table.insert(tkey,key[#key])
			table.remove(key)
			local _i = 0
			root[tkey[#tkey]],_i = loadkv(string.sub(str,i+1))
			i = i + _i + 1
		elseif char == "}" then
			if bottom and string.sub(str,bottom,bottom) == '{' then
				table.remove(stack)
			else
				break
			end
		elseif char == "/" and (not bottom or string.sub(str,bottom,bottom) ~= '\"') then
			for j = i+1,str_len do
				if string.sub(str,j,j) == '\n' then
					i = j + 1
					break
				end
			end
		else
			i = i + 1
		end

	end
	return root,i
end
function test_untis()
	local file = io.open("npc/npc_units_custom.txt")
	local data = file:read("*a")

	local root = loadkv(data).DOTAUnits

	local enemies_points = {
		boss_jiangshiwang = "boss_jiangshiwang",
		boss_diting = "boss_diting",
		boss_lingzong = "boss_lingzong",
		boss_guiwang = "boss_guiwang",
		boss_yaoxian = "boss_yaoxian",
		boss_moluojiaozhu = "boss_moluojiaozhu",
		boss_moluohufa = "boss_moluohufa",
		boss_guyao = "boss_guyao",
		boss_xueren = "boss_xueren",
		boss_pangxie = "boss_pangxie",
		--下面的这些只会被动复活
		boss_mozongzongzhu = "boss_molu",
		boss_shouhuxiong = "boss_qiyao",

		boss_molu = "boss_mozongzongzhu",
		boss_qiyao = "boss_shouhuxiong",

		boss_xiefokongxin = "boss_xiefokongxin",
		boss_xiezongshengnv = "boss_xiezongshengnv",
		boss_huoba = "boss_huoba",
		boss_yinglong = "boss_yinglong",

		creep_xiaojs = 6,
		creep_jshf = 2,
		creep_diting = 10,
		creep_lingzong = 6,
		creep_lzhf = 2, --灵宗护法
		creep_zhizhu = 3,
		creep_xzz = 9,
		creep_xueren = 6,
		creep_hbhf = 2, --火魃护法
		creep_moluojiaotu = 6,
		creep_mlhf = 2, --摩罗护法
		creep_guyao = 3,
		creep_xgy = 9,
		creep_lang = 6,
		creep_shitouren = 4,
		creep_pangxie= 9,
		creep_huoren = 6,
		creep_xiyi = 6,

	}

	for k,v in pairs(enemies_points) do
		if not root[k] then
			print(k)
		end
	end
end
local function _tostring( tab )
	local str = "["
	for k,v in pairs(tab) do
		if type(v) == 'table' then
			str = str .. _tostring(v)
		else
			str = str ..v.." , "
		end
	end
	str = str.."],"
	return str
end
function testlua(  )
	require "vscripts.libraries.minheap"
	local function cmp( a,b )
		return a.expire < b.expire
	end
	local heap = minHeap:newHeap(cmp)
	math.randomseed(os.time())
	for i=1,5 do
		local rd = math.random(1,100)
		local t = {}
		t.expire = rd
		t.name = "abc"..i
		t.ac = "abc"
		print(_tostring(t))
		heap:push(t)
	end
	print("\n\n")
	heap:print("expire")
	for i=1,6 do
		heap:pop()
		heap:print("expire")
	end

	local q = minHeap:newHeap(nil,{1,2,3,5})
	q:print()
end

function testlocalFunc(  )
	local a = "str"
	local b = 111
	local function aprint(  )
		print(a,b)
	end
	aprint()
end


function testList(  )
	local a = {
		a = 1,
		b = 2,
		c = 3
	}
	local function aaa( b )
		b.a = 0
		b.b = 0
		b.c = 0
	end
	print(a.a)
	aaa(a)
	print(a.a)
end

function testParams(  )
	local function aaa( num )
		nums = num or 1
		print(nums)
	end
	aaa()
	print(nums)
end
function testutf8(  )
	local a = io.open("npc/npc_items_custom.txt")
	local data = a:read("*a")

	for key in data:gmatch("//(.*)\n") do
		print(key)
	end
	
end

function testandor(  )
	local a = {
		aa = {a=1}
	}
	local b = a["aa"] and a["aa"].a or 0
	print(b)
end
GameRules = {}
GameRules.giveups = {}
GameRules.playerlist = {0}
function getNextx( x )
	local record = {}
	while true do
		if GameRules.giveups[x] then
			if record[x] then
				return false
			else
				record[x] = true
			end
			x = x + 1
			if x > #GameRules.playerlist then
				x = 1
			end
		else
			return GameRules.playerlist[x]
		end
	end
end
function testnegativefor(  )
	local a = 1111
	local function aa( b )
		b = nil
	end
	print(a)
	aa(a)
	print(a)
end
local MAX_LEN = 40
local function _getNextPoint( curPoint,isAnti )
	if isAnti then
		curPoint = curPoint - 1
		if curPoint < 1 then
			curPoint = MAX_LEN
		end
	else
		curPoint = curPoint + 1
		curPoint = (curPoint - 1)%MAX_LEN + 1
	end
	return curPoint
end
local function getPointSplit( curPoint,toPoint,isAnti )
	local guaijiao = {1,11,21,31}
	local ret = {}
	
	while true do
		curPoint = _getNextPoint(curPoint,isAnti)
		for i,v in ipairs(guaijiao) do
			if curPoint == v then
				table.insert(ret,curPoint)
			end
		end
		if curPoint == toPoint then
			break
		end
	end
	return ret

end

-- print(getPointSplit(1,3)[1])
-- print(getPointSplit(1,3,true)[1])
function tttt( curPoint )
	for i=1,3 do
		curPoint = curPoint - 1
		if curPoint < 1 then
			curPoint = 40
		end
	end
	print(curPoint)
end
function shallowcopy(orig)
    local orig_type = type(orig)
    local copy
    if orig_type == 'table' then
        copy = {}
        for orig_key, orig_value in pairs(orig) do
            copy[orig_key] = orig_value
        end
    else -- number, string, boolean, etc
        copy = orig
    end
    return copy
end

function ShuffledList( orig_list )
	local list = shallowcopy( orig_list )
	local result = {}
	local count = #list
	for i = 1, count do
		local pick = math.floor(math.random( 1, #list ))
		result[ #result + 1 ] = list[ pick ]
		table.remove( list, pick )
	end
	return result
end
local gold = -11
local cities = {1,2,3,4}
local mycities = {
	{city = 6,diya=false},{city = 7,diya=false}
}
local totalcities = {
	{},{},{},{},{},{},{}
}
function qqqqq()

	if not autoSell() and not autoDiya() then
		print("canot be googd")
	end
	print("final = ",gold)
end

function delvCityBy( cityid )
	
	gold = gold + cityid
	print("gold = ",gold)
end
function shCityBy( cityid )
	gold = gold + cityid
	print("gold = ",gold)
end
function autoSell(  )

	if cities[1] then
		delvCityBy(cities[1])
		
		if gold < 0 then
			return autoSell()
		else
			return true
		end
	else
		return false
	end
end

function autoDiya(  )
	if mycities[1] and mycities[1].diya == false then
		shCityBy(mycities[1].city)

		if gold < 0 then
			return autoDiya()
		else
			return true
		end
	else
		return false
	end
	
end
qqqqq()
